﻿using System;
using System.Windows.Forms;
using DoMain.SetDomain;

namespace TMIS.SetForms
{
    public partial class PasswordSetForm : Form
    {
        private readonly PasswordSetDomain _passWordDomain = new PasswordSetDomain();

        public PasswordSetForm()
        {
            InitializeComponent();
        }

        private void AlterPassword()
        {
            var result = _passWordDomain.AlterPassword(textBox_newPassword.Text);
            MessageBox.Show(result);
        }

        private void button_affirm_Click(object sender, EventArgs e)
        {
            string checkPassword = _passWordDomain.PasswordQuery();
            string oldPassword = textBox_oldPassword.Text;
            string newPassword = textBox_newPassword.Text;
            string confPassword = textBox_confPassword.Text;
            if (string.IsNullOrEmpty(oldPassword) || string.IsNullOrEmpty(newPassword) ||
                string.IsNullOrEmpty(confPassword))
            {
                MessageBox.Show(@"密码输入有为空，请检查。");
            }
            else if (!oldPassword.Equals(checkPassword))
            {
                MessageBox.Show(@"输入的旧密码有误，请检查。");
            }
            else if (!newPassword.Equals(confPassword))
            {
                MessageBox.Show(@"输入的新密码和确认密码不一致，请检查。");
            }
            else
            {
                AlterPassword();
            }
        }

        private void button_cancel_Click(object sender, EventArgs e)
        {
            Close();
        }

    }
}
